package com.example.kotlinstudy

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class FrameLayoutActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_frame_layout)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 获取 渲染的UI组件，并直接修改
        val tv = findViewById<TextView>(R.id.textView8)
        tv.textSize = 100f
        tv.text = "🍗🐷"

        // 给按钮 7绑定点击事件
        val btn = findViewById<Button>(R.id.button7)
        btn.setOnClickListener {
            Toast.makeText(this, "点你咋地~", Toast.LENGTH_SHORT).show()
        }
        // 给按钮 8绑定点击事件
        val btn8 = findViewById<Button>(R.id.button8)
        btn8.setOnClickListener(this)
    }

    // 写这里会闪退
    // val tv = findViewById<TextView>(R.id.textView8)


    fun onBtnClick(view: View) {
        // 轻提示
        Toast.makeText(this, "点我干啥", Toast.LENGTH_SHORT).show()
        val tv = findViewById<TextView>(R.id.textView8)
        tv.text = "🐟🦆"
    }

    // 实现 View.OnClickListener 接口中的 方法
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.button8 -> {
                Toast.makeText(this, "就要点你~🏀", Toast.LENGTH_SHORT).show()
            }
        }
    }
}